package com.example.b_308.software.service;

import android.content.Context;

import com.example.b_308.software.OfficeContent;
import com.example.b_308.software.OfficeResult;
import com.example.b_308.software.comment.view.title.OfficeApplication;
import com.example.b_308.software.comment.view.title.util.SharedPreferencesUtils;
import com.example.b_308.software.model.Staff;
import com.example.b_308.software.view.base.INetCallBack;

/**
 * Created by B-308 on 2017/11/28.
 */
public class UserService extends BaseService {
  static  Staff userDao;
    IUserView iUserView;

    public UserService(IUserView iUserView) {
        this.iUserView = iUserView;
        userDao= SharedPreferencesUtils.getObj(OfficeApplication.getInstance(),Staff.USER_TAG,Staff.class);
        if(null==userDao){
            userDao=new Staff();
        }
    }

    public void login(Staff staff){
        userDao.postData("/user/login",staff,new INetCallBack(){
            @Override
            public void onNetCallBack(OfficeResult officeResult) {
            if(OfficeContent.SUCCESS_CODE==officeResult.code){
                userDao=new Staff(officeResult.data);
                iUserView.loginSuccess(userDao);
            }else{
                iUserView.fail(officeResult.message);
            }
            }
        });

    }
    public void register(Staff staff){
        userDao.postData("/user/login",staff,new INetCallBack(){

            @Override
            public void onNetCallBack(OfficeResult officeResult) {
                if(OfficeContent.SUCCESS_CODE==officeResult.code){
                    userDao=new Staff(officeResult.data);
                    iUserView.registerSuccess(userDao);
                }else{
                    iUserView.fail(officeResult.message);
                }
            }
        });
}
    public  void getCode(Staff staff){
        userDao.postData("/user/login",staff,new INetCallBack(){

            @Override
            public void onNetCallBack(OfficeResult officeResult) {
                if(OfficeContent.SUCCESS_CODE==officeResult.code){
                    userDao=new Staff(officeResult.data);
                    iUserView.getCodeSuccess();
                }else{
                    iUserView.fail(officeResult.message);
                }
            }
        });
    }
    public void loginDefault(){

    }
}

